package apple

import (
	"crypto/ecdsa"
	"crypto/elliptic"
	"crypto/rand"
	"crypto/sha256"
	"encoding/hex"
	"fmt"
	"testing"

	"github.com/go-pay/xlog"
)

func TestExample(t *testing.T) {
	privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
	if err != nil {
		panic(err)
	}
	xlog.Warnf("%+v", privateKey)

	msg := "hello, world"
	hash := sha256.Sum256([]byte(msg))

	sig, err := ecdsa.SignASN1(rand.Reader, privateKey, hash[:])
	if err != nil {
		panic(err)
	}
	fmt.Printf("signature: %x\n", sig)
	fmt.Printf("signature2: %s\n", hex.EncodeToString(sig))

	valid := ecdsa.VerifyASN1(&privateKey.PublicKey, hash[:], sig)
	fmt.Println("signature verified:", valid)
}

func TestExtractClaims(t *testing.T) {
	signedPayload := "eyJhbGciOiJFUzI1NiIsIng1YyI6WyJNSUlFTURDQ0E3YWdBd0lCQWdJUWFQb1BsZHZwU29FSDBsQnJqRFB2OWpBS0JnZ3Foa2pPUFFRREF6QjFNVVF3UWdZRFZRUURERHRCY0hCc1pTQlhiM0pzWkhkcFpHVWdSR1YyWld4dmNHVnlJRkpsYkdGMGFXOXVjeUJEWlhKMGFXWnBZMkYwYVc5dUlFRjFkR2h2Y21sMGVURUxNQWtHQTFVRUN3d0NSell4RXpBUkJnTlZCQW9NQ2tGd2NHeGxJRWx1WXk0eEN6QUpCZ05WQkFZVEFsVlRNQjRYRFRJeE1EZ3lOVEF5TlRBek5Gb1hEVEl6TURreU5EQXlOVEF6TTFvd2daSXhRREErQmdOVkJBTU1OMUJ5YjJRZ1JVTkRJRTFoWXlCQmNIQWdVM1J2Y21VZ1lXNWtJR2xVZFc1bGN5QlRkRzl5WlNCU1pXTmxhWEIwSUZOcFoyNXBibWN4TERBcUJnTlZCQXNNSTBGd2NHeGxJRmR2Y214a2QybGtaU0JFWlhabGJHOXdaWElnVW1Wc1lYUnBiMjV6TVJNd0VRWURWUVFLREFwQmNIQnNaU0JKYm1NdU1Rc3dDUVlEV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mpkR2x2YmlJc0luUnlZVzV6WVdOMGFXOXVVbVZoYzI5dUlqb2lVRlZTUTBoQlUwVWlMQ0p6ZEc5eVpXWnliMjUwSWpvaVEwaE9JaXdpYzNSdmNtVm1jbTl1ZEVsa0lqb2lNVFF6TkRZMUluMC5hM09PRTNGcGxPdF9UQV9nQURzNW1rM2JRNWdKUDJubFdWX2hfN2xKRUMtcjNCZDh0d2ItSzFuQm5KR3hGVW9OeVRibWp3YXZOcDhPUHM5bGw4cGhfZyJ9LCJ2ZXJzaW9uIjoiMi4wIiwic2lnbmVkRGF0ZSI6MTY4Nzk0MTUxMjU2MH0.Tz4bvMOb-AT88is_pobjyOBZxwIKDkyugOQ4BqfTbhrlRNgKaZ-upGRTJlydJrUM9aRfdezRc0-1ekmMwcndcA"
	np := &NotificationV2Payload{}
	err = ExtractClaims(signedPayload, np)
	if err != nil {
		xlog.Error(err)
		return
	}
	xlog.Infof("np:%+v", np)
	xlog.Infof("np.data:%+v", np.Data)
	ti, err := np.DecodeTransactionInfo()
	if err != nil {
		xlog.Error(err)
		return
	}
	xlog.Infof("ti:%+v", ti.TransactionId)
	/*
		{
		  "transactionId": "510001261072921",
		  "originalTransactionId": "510001261072921",
		  "bundleId": "com.jrjj.keysns",
		  "productId": "com.keysns.JR1200",
		  "purchaseDate": 1687239036000,
		  "originalPurchaseDate": 1687239036000,
		  "quantity": 1,
		  "type": "Consumable",
		  "inAppOwnershipType": "PURCHASED",
		  "signedDate": 1687941512573,
		  "environment": "Production",
		  "transactionReason": "PURCHASE",
		  "storefront": "CHN",
		  "storefrontId": "143465"
		}
	*/
}

func TestExtractClaimsToken(t *testing.T) {
	signedPayload := "eyJhbGciOiJFUzI1NiIsIng1YyI6WyJNSUlFTURDQ0E3YWdBd0lCQWdJUWFQb1BsZHZwU29FSDBsQnJqRFB2OWpBS0JnZ3Foa2pPUFFRREF6QjFNVVF3UWdZRFZRUURERHRCY0hCc1pTQlhiM0pzWkhkcFpHVWdSR1YyWld4dmNHV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dsdmJrbGtJam9pTlRFd01EQXhNall4TURjeU9USXhJaXdpWW5WdVpHeGxTV1FpT2lKamIyMHVhbkpxYWk1clpYbHpibk1pTENKd2NtOWtkV04wU1dRaU9pSmpiMjB1YTJWNWMyNXpMa3BTTVRJd01DSXNJbkIxY21Ob1lYTmxSR0YwWlNJNk1UWTROekl6T1RBek5qQXdNQ3dpYjNKcFoybHVZV3hRZFhKamFHRnpaVVJoZEdVaU9qRTJPRGN5TXprd016WXdNREFzSW5GMVlXNTBhWFI1SWpveExDSjBlWEJsSWpvaVEyOXVjM1Z0WVdKc1pTSXNJbWx1UVhCd1QzZHVaWEp6YUdsd1ZIbHdaU0k2SWxCVlVrTklRVk5GUkNJc0luTnBaMjVsWkVSaGRHVWlPakUyT0RjNU5ERTFNVEkxTnpNc0ltVnVkbWx5YjI1dFpXNTBJam9pVUhKdlpIVmpkR2x2YmlJc0luUnlZVzV6WVdOMGFXOXVVbVZoYzI5dUlqb2lVRlZTUTBoQlUwVWlMQ0p6ZEc5eVpXWnliMjUwSWpvaVEwaE9JaXdpYzNSdmNtVm1jbTl1ZEVsa0lqb2lNVFF6TkRZMUluMC5hM09PRTNGcGxPdF9UQV9nQURzNW1rM2JRNWdKUDJubFdWX2hfN2xKRUMtcjNCZDh0d2ItSzFuQm5KR3hGVW9OeVRibWp3YXZOcDhPUHM5bGw4cGhfZyJ9LCJ2ZXJzaW9uIjoiMi4wIiwic2lnbmVkRGF0ZSI6MTY4Nzk0MTUxMjU2MH0.Tz4bvMOb-AT88is_pobjyOBZxwIKDkyugOQ4BqfTbhrlRNgKaZ-upGRTJlydJrUM9aRfdezRc0-1ekmMwcndcA"
	np := &NotificationV2Payload{}
	tk, err := ExtractClaimsToken(signedPayload, np)
	if err != nil {
		xlog.Error(err)
		return
	}
	xlog.Infof("np:%+v", np)
	xlog.Infof("np.data:%+v", np.Data)

	// Print token segments, verify the integrity of original data.
	for i := 0; i < len(tk.TokenSegmentRows); i++ {
		xlog.Infof("token_raw[%d]:%s\n", i, tk.TokenSegmentRows[i])
	}

	ti, err := np.DecodeTransactionInfo()
	if err != nil {
		xlog.Error(err)
		return
	}
	xlog.Infof("ti:%+v", ti.TransactionId)
	xlog.Infof("ti_info:%+v\n", ti)

	ot, err := ExtractClaimsToken(np.Data.SignedTransactionInfo, &TransactionInfo{})
	if err != nil {
		xlog.Error(err)
		return
	}

	// 解析数据[ti_info] 与 原始数据[ot_info] 对比, 确保数据结构体可以完全解析, 版本更新后确认数据一致性场景下会有帮助作用.
	xlog.Infof("ot_info:%s\n", ot.TokenSegmentRows[1])

	/*
		{
		  "transactionId": "510001261072921",
		  "originalTransactionId": "510001261072921",
		  "bundleId": "com.jrjj.keysns",
		  "productId": "com.keysns.JR1200",
		  "purchaseDate": 1687239036000,
		  "originalPurchaseDate": 1687239036000,
		  "quantity": 1,
		  "type": "Consumable",
		  "inAppOwnershipType": "PURCHASED",
		  "signedDate": 1687941512573,
		  "environment": "Production",
		  "transactionReason": "PURCHASE",
		  "storefront": "CHN",
		  "storefrontId": "143465"
		}
	*/
}

func ExampleExtractClaimsToken() {
	signedPayload := "eyJhbGciOi......upGRTJlydJrUM9aRfdezRc0-1ekmMwcndcA"
	np := &NotificationV2Payload{}
	tk, err := ExtractClaimsToken(signedPayload, np)
	xlog.Errorf("err:%+v\n", err)
	xlog.Infof("token:%+v\n", tk)
	xlog.Infof("np:%+v\n", np)

	// Output:
	//	- err: error, invalid message.
	// 	- token: *jwt.Token, &jwt.Token{...}
	// 	- np: *apple.NotificationV2Payload, &apple.NotificationV2Payload{...}
}
